<?
require_once("inc_security.php");
//check quyền them sua xoa
checkAddEdit("add");

	//Khai bao Bien
	$after_save_data						= getValue("after_save_data", "str", "POST", "add.php");
    
	$far_name								= getValue("far_name","str","GET","");
    $far_content							= getValue("far_content","str","GET","");
	$far_fac_id								= getValue("far_fac_id","int","GET",'0');
    
    //Call Class generate_form();
	$myform 									= new generate_form();
	//Loại bỏ chuc nang thay the Tag Html
	$myform->removeHTML(0);
	$myform->add("far_name","far_name", 0, 0, $far_name, 1, translate_text("Tên câu hỏi không được để trống"), 0, "");
    $myform->add("far_content","far_content", 0, 0, $far_content, 1, translate_text("Nội dung không được để trống"), 0, "");
    $myform->add("far_fac_id", "far_fac_id", 1, 0, $far_fac_id, 1, translate_text("Vui lòng chọn danh mục"),0,"");
    
    $cateop = get_all_faq_cate_options();
	
	//Add table
	$myform->addTable($fs_table);
	//Warning Error!
	$errorMsg = "";
	//Get Action.
	$action	= getValue("action", "str", "POST", "");
	if($action == "execute"){
		$errorMsg .= $myform->checkdata();
		if($errorMsg == ""){
			$db_ex 	= new db_execute_return();
            
			$last_id = $db_ex->db_execute($myform->generate_insert_SQL());
            
			// Redirect to add new
			redirect($after_save_data);
			exit();
		}
	}
	//add form for javacheck
	$myform->addFormname("add_new");
	$myform->evaluate();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<?=$load_header?>
<? $myform->checkjavascript();?>
</head>
<body topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<? /*------------------------------------------------------------------------------------------------*/ ?>
<?=template_top(translate_text("Add_new_category"))?>
<? /*------------------------------------------------------------------------------------------------*/ ?>
	<p align="center" style="padding-left:10px;">
	<?
	$form = new form();
	$form->create_form("faq_add", $_SERVER["REQUEST_URI"], "post", "multipart/form-data",'onsubmit="validateForm(); return false;"');
	$form->create_table();
	?>
	<?=$form->text_note('Những ô dấu (<font class="form_asterisk">*</font>) là bắt buộc phải nhập.')?>
	<?=$form->errorMsg($errorMsg)?>
    
	<?=$form->text("Câu hỏi", "far_name", "far_name", $far_name, "Câu hỏi", 1, 250, "", 255, "", "", "")?>
    <?=$form->select("Danh mục", "far_fac_id", "far_fac_id", $cateop, $far_fac_id, "Danh mục", 0, 250, 1, 0,  "", "")?>
    <? $form->close_table();?>
    <?=$form->tinyMCE("Nội dung", "far_content", "far_content", $far_content)?>
    <?=$form->create_table();?>
	<?=$form->radio("Sau khi lưu dữ liệu", "add_new" . $form->ec . "return_listing", "after_save_data", $add . $form->ec . $listing, $after_save_data, "Thêm mới" . $form->ec . "Quay về danh sách", 0, $form->ec, "");?>
	<?=$form->button("submit" . $form->ec . "reset", "submit" . $form->ec . "reset", "submit" . $form->ec . "reset", "Cập nhật" . $form->ec . "Làm lại", "Cập nhật" . $form->ec . "Làm lại", 'style="background:url(' . $fs_imagepath . 'button_1.gif) no-repeat"' . $form->ec . 'style="background:url(' . $fs_imagepath . 'button_2.gif)"', "");?>
	<?=$form->hidden("action", "action", "execute", "");?>
	<?
	$form->close_table();
	$form->close_form();
	unset($form);
	?>
	</p>
<?=template_bottom() ?>
<? /*------------------------------------------------------------------------------------------------*/ ?>
</body>
</html>